using System.Data;
using System;
using Library.Business;
using NhatThanhSoftware;
namespace Library.Controller
{
    public partial class Controller_HoaDonNuoc: Cls_HoaDonNuoc
    {
        /// <summary>
        /// Set du lieu
        /// </summary>
        private static void setHoaDonNuoc(ref Cls_HoaDonNuoc HoaDonNuoc, DataRow dr)
        {
            HoaDonNuoc.ID_KhachHang = Convert.ToInt32(dr[Cls_HoaDonNuoc.fn_ID_KhachHang] ) ;
            HoaDonNuoc.ID_HeThongNuoc = dr[Cls_HoaDonNuoc.fn_ID_HeThongNuoc].ToString() ;
            HoaDonNuoc.MaSoHoaDon = Convert.ToDouble(dr[Cls_HoaDonNuoc.fn_MaSoHoaDon] ) ;
            HoaDonNuoc.Thang = Convert.ToInt32(dr[Cls_HoaDonNuoc.fn_Thang] ) ;
            HoaDonNuoc.Nam = Convert.ToInt32(dr[Cls_HoaDonNuoc.fn_Nam] ) ;
            HoaDonNuoc.DauKy = Convert.ToInt32(dr[Cls_HoaDonNuoc.fn_DauKy] ) ;
            HoaDonNuoc.CuoiKy = Convert.ToInt32(dr[Cls_HoaDonNuoc.fn_CuoiKy] ) ;
            HoaDonNuoc.SoM3TieuThu = Convert.ToInt32(dr[Cls_HoaDonNuoc.fn_SoM3TieuThu] ) ;
            HoaDonNuoc.ThanhTien = Convert.ToDouble(dr[Cls_HoaDonNuoc.fn_ThanhTien] ) ;
            HoaDonNuoc.ThueGTGT = Convert.ToDouble(dr[Cls_HoaDonNuoc.fn_ThueGTGT] ) ;
            HoaDonNuoc.TienThueGTGT = Convert.ToDouble(dr[Cls_HoaDonNuoc.fn_TienThueGTGT] ) ;
            HoaDonNuoc.TienThue_1 = Convert.ToDouble(dr[Cls_HoaDonNuoc.fn_TienThue_1] ) ;
            HoaDonNuoc.TienThue_2 = Convert.ToDouble(dr[Cls_HoaDonNuoc.fn_TienThue_2] ) ;
            HoaDonNuoc.TienPhi_1 = Convert.ToDouble(dr[Cls_HoaDonNuoc.fn_TienPhi_1] ) ;
            HoaDonNuoc.TienPhi_2 = Convert.ToDouble(dr[Cls_HoaDonNuoc.fn_TienPhi_2] ) ;
            HoaDonNuoc.TongCongThanhTien = Convert.ToDouble(dr[Cls_HoaDonNuoc.fn_TongCongThanhTien] ) ;
            HoaDonNuoc.Hidden = Convert.ToBoolean(dr[Cls_HoaDonNuoc.fn_Hidden] ) ;
        }
        /// <summary>
        /// Lưu dữ liệu
        /// </summary>
        /// <param name="dtData">Datatable</param>
        /// <returns>TRUE;FALSE</returns>
        public static bool doSAVE(DataTable dtData)
        {
            if (dtData.GetChanges() == null) return false;
            foreach( DataRow dr in dtData.GetChanges().Rows )
            {
                Cls_HoaDonNuoc HoaDonNuoc = new Cls_HoaDonNuoc();
                try
                {
                    switch(dr.RowState)
                    {
                        case DataRowState.Modified:
                            setHoaDonNuoc(ref HoaDonNuoc, dr);
                            HoaDonNuoc.ID_HoaDonNuoc_find =Convert.ToInt32(dr[Cls_HoaDonNuoc.fn_ID_HoaDonNuoc] );
                            HoaDonNuoc.ID_HoaDonNuoc=HoaDonNuoc.ID_HoaDonNuoc_find;
                            HoaDonNuoc.doUpdate();
                            break;
                        case DataRowState.Added:
                            setHoaDonNuoc(ref HoaDonNuoc, dr);
                            HoaDonNuoc.doInsert();
                            break;
                        case DataRowState.Deleted:
                            HoaDonNuoc.ID_HoaDonNuoc_find =Convert.ToInt32(dr[Cls_HoaDonNuoc.fn_ID_HoaDonNuoc, DataRowVersion.Original] );
                            HoaDonNuoc.doDelete();
                            break;
                    }
                }
                catch (Exception ex)
                {
                    ThongBao.msgThongBao(HoaDonNuoc.ID_HoaDonNuoc + " chưa lưu được, click nút [OK] để lưu tiếp.");
                }
        }
        return true;
        }
        /// <summary>
        /// Check dữ liệu
        /// </summary>
        /// <param name="dtData">Datatable</param>
        /// <returns>TRUE;FALSE</returns>}
        public static void doCHECK(DataTable dtData)
        {
            if (dtData.GetChanges() == null) return;
            DataRowCollection drColection = dtData.GetChanges().Rows;
            foreach (DataRow dr in drColection)
            {
                if (dr.RowState == DataRowState.Deleted) break;
                string strID_HoaDonNuoc = dr[Cls_HoaDonNuoc.fn_ID_HoaDonNuoc].ToString();
                if (dr.RowState == DataRowState.Added)
                {
                }
            }
        }
    }
}
